/**
* Copyright (c) 2004-2013 Luciano Xumerle. All rights reserved.
*
* This file is part of gephinfo.
*
* gephinfo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

package it.ciano.util;

import java.util.*;

/**
 * The class extends ArrayList and implements a list of unique element.
 *
 * @author Luciano Xumerle
 * @version 0.0.2
 */
public class FieldList extends ArrayList
{

    static final long serialVersionUID = 8040277032333912896L;

    /**
     * Constructs an empty list with an initial capacity of ten.
     */
    public FieldList()
    {
        super();
    }

    /**
     * Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
     *
     * @param c the collection whose elements are to be placed into this list.
     */
    public FieldList ( Collection c )
    {
        super ( c );
    }

    /**
     * Constructs an empty list with the specified initial capacity.
     *
     * @param initialCapacity the initial capacity of the list.
     */
    public FieldList ( int initialCapacity )
    {
        super ( initialCapacity );
    }

    /**
     * Overrides add() method.
     *
     * @param o the Object.
     * @return the boolean.
     */
    public boolean add
    ( Object o )
    {
        for ( int i = 0; i < size(); i++ )
            if ( o.equals ( ( Object ) this.get ( i ) ) )
                return false;
        super.add ( o );
        return true;
    }

    /**
     * Returns the array with every Fields String.
     *
     * @return a String array. Returns null if there are 0 Fields.
     */
    public String[] getFields()
    {
        if ( size() > 0 )
        {
            String a[] = new String[ size() ];
            for ( int i = 0; i < this.size(); i++ )
                a[ i ] = this.get ( i ).toString();
            return a;
        }
        return null;
    }

} // end class


